package org.sja.log2traffic;

import org.sja.log2traffic.DataCalculator;
import org.sja.log2traffic.dataStructures.CategoryTrackerEntity;
import org.sja.log2traffic.dataStructures.DateAndResponseTimeEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class CategoryTrackerTest {

	private CategoryTrackerEntity categoryTrackerImpl;
	private DataCalculator dataCalculator;

	@BeforeMethod
	public void beforeMehtod() {
		categoryTrackerImpl = new CategoryTrackerEntity();
		dataCalculator = new DataCalculator();
	}

	@Test
	public void getSortedByCountTest1() {
		DateAndResponseTimeEntity dateAndResponseTime1 = new DateAndResponseTimeEntity(dataCalculator.stringWithMilisToLong("2012-01-01 12:00:00,000"), 100L);
		DateAndResponseTimeEntity dateAndResponseTime2 = new DateAndResponseTimeEntity(dataCalculator.stringWithMilisToLong("2012-01-01 13:00:00,000"), 301L);
		DateAndResponseTimeEntity dateAndResponseTime3 = new DateAndResponseTimeEntity(dataCalculator.stringWithMilisToLong("2012-01-01 14:00:00,000"), 300L);
		categoryTrackerImpl.foundCategory("AAA", dateAndResponseTime1);
		categoryTrackerImpl.foundCategory("CCC", dateAndResponseTime2);
		categoryTrackerImpl.foundCategory("AAA", dateAndResponseTime3);
		
		Assert.assertEquals(categoryTrackerImpl.getSortedByCount().length, 2);
		
		Assert.assertEquals(categoryTrackerImpl.getSortedByCount()[0].getCategory(),"AAA");
		Assert.assertEquals(categoryTrackerImpl.getSortedByCount()[0].getCount().longValue(),2);
		Assert.assertEquals(dataCalculator.longToStringWithMilis(categoryTrackerImpl.getSortedByCount()[0].getMaxDateAndTime().getDate()),"2012-01-01 14:00:00,000");
		Assert.assertEquals(categoryTrackerImpl.getSortedByCount()[0].getMaxDateAndTime().getResponseTime().longValue(),300);

		Assert.assertEquals(categoryTrackerImpl.getSortedByCount()[1].getCategory(),"CCC");
		Assert.assertEquals(categoryTrackerImpl.getSortedByCount()[1].getCount().longValue(),1);
		Assert.assertEquals(dataCalculator.longToStringWithMilis(categoryTrackerImpl.getSortedByCount()[1].getMaxDateAndTime().getDate()),"2012-01-01 13:00:00,000");
		Assert.assertEquals(categoryTrackerImpl.getSortedByCount()[1].getMaxDateAndTime().getResponseTime().longValue(),301);
		
		
	}
	
}
